package com.zz.parkingsystem.config;

import com.zz.parkingsystem.interceptor.AdminLoginInterceptor;
import com.zz.parkingsystem.interceptor.InspectorLoginInterceptor;
import com.zz.parkingsystem.interceptor.UserLoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

/*    @Autowired
    private AdminLoginInterceptor adminLoginInterceptor;
    @Autowired
    private UserLoginInterceptor userLoginInterceptor;
    @Autowired
    private InspectorLoginInterceptor inspectorLoginInterceptor;*/
    /**
     * 解决cros同源问题
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
                .maxAge(3600)
                .allowCredentials(true);
    }

    /**
     * 注册拦截请求
     * @param registry 注册器
     */
/*    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册管理员登陆
       registry.addInterceptor(adminLoginInterceptor)
               .addPathPatterns("/admin/**")
               .excludePathPatterns("/admin/login");
       //注册用户登陆
       registry.addInterceptor(userLoginInterceptor)
                .addPathPatterns("/user/**")
                .excludePathPatterns("/user/login");

       registry.addInterceptor(inspectorLoginInterceptor)
                .addPathPatterns("/inspector/**")
                .excludePathPatterns("/inspector/login");

    }*/
}
